Move shortcut manager initialization code
authorMatthias Clasen <mclasen@redhat.com>
Sun, 15 Mar 2020 21:38:56 +0000 (17:38 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 19 Mar 2020 03:00:51 +0000 (23:00 -0400)
It is just too ugly to use quarks across multiple
source files, so add a private helper function that
attaches the controllers.

gtk/gtkshortcutmanager.c
gtk/gtkshortcutmanagerprivate.h [new file with mode: 0644]
gtk/gtkwidget.c

index db97448b6782a433cb24fc1f86b32b92a20a3800..4a8680e10451f3266b43555948f313d813a49678 100644 (file)
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include "gtkshortcutmanager.h"
+#include "gtkshortcutmanagerprivate.h"
 #include "gtkconcatmodelprivate.h"
 
 /**
 
 G_DEFINE_INTERFACE (GtkShortcutManager, gtk_shortcut_manager, G_TYPE_OBJECT)
 
+void
+gtk_shortcut_manager_create_controllers (GtkWidget *widget)
+{
+  GtkConcatModel *model;
+  GtkEventController *controller;
+
+  model = gtk_concat_model_new (GTK_TYPE_SHORTCUT);
+  g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
+  controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
+  gtk_widget_add_controller (widget, controller);
+
+  model = gtk_concat_model_new (GTK_TYPE_SHORTCUT);
+  g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
+  controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
+  gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
+  gtk_widget_add_controller (widget, controller);
+}
+
 static GtkConcatModel *
 gtk_shortcut_manager_get_model (GtkShortcutManager  *self,
                                 GtkPropagationPhase  phase)
diff --git a/gtk/gtkshortcutmanagerprivate.h b/gtk/gtkshortcutmanagerprivate.h
new file mode 100644 (file)
index 0000000..72424db
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef __GTK_SHORTCUT_MANAGER_PRIVATE_H__
+#define __GTK_SHORTCUT_MANAGER__PRIVATE_H__
+
+#include "gtkshortcutmanager.h"
+
+G_BEGIN_DECLS
+
+void gtk_shortcut_manager_create_controllers (GtkWidget *widget);
+
+G_END_DECLS
+
+#endif /* __GTK_SHORTCUT_MANAGER_PRIVATE_H__ */
index 8e82a3587202ade199b8d7897268d10801a2a501..121d3f5e62ae425937fade1a9d8c967e7e2e9a12 100644 (file)
@@ -61,6 +61,7 @@
 #include "gtkshortcut.h"
 #include "gtkshortcutcontrollerprivate.h"
 #include "gtkshortcutmanager.h"
+#include "gtkshortcutmanagerprivate.h"
 #include "gtkshortcuttrigger.h"
 #include "gtksizegroup-private.h"
 #include "gtksnapshotprivate.h"
@@ -2460,20 +2461,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
     priv->root = (GtkRoot *) widget;
 
   if (g_type_is_a (G_TYPE_FROM_CLASS (g_class), GTK_TYPE_SHORTCUT_MANAGER))
-    {
-      GtkConcatModel *model;
-      
-      model = gtk_concat_model_new (GTK_TYPE_SHORTCUT);
-      g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
-      controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
-      gtk_widget_add_controller (widget, controller);
-
-      model = gtk_concat_model_new (GTK_TYPE_SHORTCUT);
-      g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
-      controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
-      gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
-      gtk_widget_add_controller (widget, controller);
-    }
+    gtk_shortcut_manager_create_controllers (widget);
 
   layout_manager_type = gtk_widget_class_get_layout_manager_type (g_class);
   if (layout_manager_type != G_TYPE_INVALID)